using Perfect.Marshal;
using System.Xml;

namespace editor
{
namespace cfg.skill
{
[System.Serializable]
public  class Rectangle : HitArea
 {

    public float width ;
     public float height ;
     public float offsetX ;
     public float offsetZ ;
     public float offsetAngle ;
     


    public const int TYPE_ID = 528158824;

    public override int GetTypeId() {
        return TYPE_ID;
    }


    public override void MarshalCompatible(Perfect.Marshal.Octets os) {
        os.WriteSize(8);
        os.WriteSize(Tag.INT | (1 << Tag.TAG_SHIFT));  os.WriteInt(maxTargetNum);  
         os.WriteSize(Tag.FLOAT | (2 << Tag.TAG_SHIFT));  os.WriteFloat(minHeight);  
         os.WriteSize(Tag.FLOAT | (3 << Tag.TAG_SHIFT));  os.WriteFloat(maxHeight);  
         os.WriteSize(Tag.FLOAT | (4 << Tag.TAG_SHIFT));  os.WriteFloat(width);  
         os.WriteSize(Tag.FLOAT | (5 << Tag.TAG_SHIFT));  os.WriteFloat(height);  
         os.WriteSize(Tag.FLOAT | (6 << Tag.TAG_SHIFT));  os.WriteFloat(offsetX);  
         os.WriteSize(Tag.FLOAT | (7 << Tag.TAG_SHIFT));  os.WriteFloat(offsetZ);  
         os.WriteSize(Tag.FLOAT | (8 << Tag.TAG_SHIFT));  os.WriteFloat(offsetAngle);  
         
    }

    public override void UnmarshalCompatible(Perfect.Marshal.Octets os) {
        for (int _var_num_ = os.ReadSize(); _var_num_-- > 0; ) {
            int _id_ = os.ReadSize();
            switch (_id_)
            {
            case (Tag.INT | (1 << Tag.TAG_SHIFT)):   maxTargetNum = os.ReadInt(); break;  
             case (Tag.FLOAT | (2 << Tag.TAG_SHIFT)):   minHeight = os.ReadFloat(); break;  
             case (Tag.FLOAT | (3 << Tag.TAG_SHIFT)):   maxHeight = os.ReadFloat(); break;  
             case (Tag.FLOAT | (4 << Tag.TAG_SHIFT)):   width = os.ReadFloat(); break;  
             case (Tag.FLOAT | (5 << Tag.TAG_SHIFT)):   height = os.ReadFloat(); break;  
             case (Tag.FLOAT | (6 << Tag.TAG_SHIFT)):   offsetX = os.ReadFloat(); break;  
             case (Tag.FLOAT | (7 << Tag.TAG_SHIFT)):   offsetZ = os.ReadFloat(); break;  
             case (Tag.FLOAT | (8 << Tag.TAG_SHIFT)):   offsetAngle = os.ReadFloat(); break;  
             
            default: Tag.SkipUnknownField(_id_, os); break;
            }
         }
    }
    public override void MarshalXml(XmlWriter ele)
    {
        ele.WriteAttributeString("type", "Rectangle");
        ele.WriteStartElement("maxTargetNum"); ele.WriteAttributeString("id", "1"); ele.WriteInt(maxTargetNum); ele.WriteEndElement();
         ele.WriteStartElement("minHeight"); ele.WriteAttributeString("id", "2"); ele.WriteFloat(minHeight); ele.WriteEndElement();
         ele.WriteStartElement("maxHeight"); ele.WriteAttributeString("id", "3"); ele.WriteFloat(maxHeight); ele.WriteEndElement();
         ele.WriteStartElement("width"); ele.WriteAttributeString("id", "4"); ele.WriteFloat(width); ele.WriteEndElement();
         ele.WriteStartElement("height"); ele.WriteAttributeString("id", "5"); ele.WriteFloat(height); ele.WriteEndElement();
         ele.WriteStartElement("offsetX"); ele.WriteAttributeString("id", "6"); ele.WriteFloat(offsetX); ele.WriteEndElement();
         ele.WriteStartElement("offsetZ"); ele.WriteAttributeString("id", "7"); ele.WriteFloat(offsetZ); ele.WriteEndElement();
         ele.WriteStartElement("offsetAngle"); ele.WriteAttributeString("id", "8"); ele.WriteFloat(offsetAngle); ele.WriteEndElement();
         
    }

    public override void UnmarshalXml(XmlElement ele)
    {
        foreach (XmlElement e in ele.GetChildren())
        {
            if (int.TryParse(ele.GetAttribute("id"), out var _id_))
            {
                switch (_id_)
                {
                case 1:  maxTargetNum = ele.ReadInt(); break; 
                 case 2:  minHeight = ele.ReadFloat(); break; 
                 case 3:  maxHeight = ele.ReadFloat(); break; 
                 case 4:  width = ele.ReadFloat(); break; 
                 case 5:  height = ele.ReadFloat(); break; 
                 case 6:  offsetX = ele.ReadFloat(); break; 
                 case 7:  offsetZ = ele.ReadFloat(); break; 
                 case 8:  offsetAngle = ele.ReadFloat(); break; 
                 
                default: break;
                }
            }
            else
            {
                switch (e.Name)
                {
                case "max_target_num":  maxTargetNum = ele.ReadInt(); break; 
                 case "min_height":  minHeight = ele.ReadFloat(); break; 
                 case "max_height":  maxHeight = ele.ReadFloat(); break; 
                 case "width":  width = ele.ReadFloat(); break; 
                 case "height":  height = ele.ReadFloat(); break; 
                 case "offset_x":  offsetX = ele.ReadFloat(); break; 
                 case "offset_z":  offsetZ = ele.ReadFloat(); break; 
                 case "offset_angle":  offsetAngle = ele.ReadFloat(); break; 
                 
                default: break;
                }
            }
        }
    }
}
}
}
